// 监听玩家屏幕分辨率产生变化事件
screen.events.add('resize', ({ screenWidth, screenHeight }) => {
    const evt = navigator.getDeviceInfo() // 导航器，现在用不到。
    scaleScreen(screenWidth, screenHeight);
})

// 作者的屏幕的分辨率，以此为标准大小。
const setupScale = {
    x: 1919,
    y: 1030,
}
const uis = UiScreen.getAllScreen()
function scaleScreen(sH: any, sW: any) {
    remoteChannel.sendServerEvent({
        type: "screen",
        data: {
            screenWidth: sW,
            screenHeight: sH
        }
    })
    let widthScaleFactor = 1
    if ((sW + sH) / 2 < (setupScale.x + setupScale.y) / 2) {
        widthScaleFactor = (sW + sH) / (setupScale.x + setupScale.y);
    }

    uis.forEach((e) => {
        if (!e.uiScale) e.uiScale = UiScale.create();
        e.uiScale.scale = widthScaleFactor;
    })
    console.log("screen:", sW, 'x', sH);

}
//进入游戏时设置缩放一次
scaleScreen(screenHeight, screenWidth)